package com.loong.game2048.server.impl;

import com.loong.game2048.Exception.BizException;
import com.loong.game2048.dao.ScopeDao;
import com.loong.game2048.module.Scope;
import com.loong.game2048.module.vo.ScopeVo;
import com.loong.game2048.server.ScopeService;
import com.loong.game2048.util.StrUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author lyx
 * @date 2020/5/22 11:59
 */
@Service
public class ScopeServiceImpl implements ScopeService {

    @Resource
    private ScopeDao scopeDao;

    @Override
    public Integer scopeHasExit(String userId) {
        return scopeDao.scopeHasExit(userId);
    }

    @Override
    public Integer addScope(String userId, Integer gameId, Integer scope) {
        if (!StrUtils.strIsEmpty(userId)&&gameId!=null&&scope!=null){
            return scopeDao.addScope(userId, gameId, scope);
        }
        throw new BizException("参数缺失");
    }

    @Override
    public Integer updateScope(String userId, Integer gameId, Integer scope) {
        if (!StrUtils.strIsEmpty(userId)&&gameId!=null&&scope!=null){
            return scopeDao.updateScope(userId, gameId, scope);
        }
        throw new BizException("参数缺失");
    }

    @Override
    public List<Scope> getAllScope() {
        return scopeDao.getAllSCope();
    }

    @Override
    public Integer getScope(String userId, Integer gameId) {
        return scopeDao.getScope(userId, gameId);
    }

    @Override
    public ScopeVo getScopeVo(String userId, Integer gameId) {
        ScopeVo scopeVo = new ScopeVo();
        Integer scope = scopeDao.getScope(userId, gameId);
        scopeVo.setScope(scope);
        scopeVo.setSort(scopeDao.getScopeSort(gameId,scope)+1);
        return scopeVo;
    }
}
